﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClusterAggregation.Datum
{
    /**
     * general implementation of a greyscaled pixel
     */
    public class CPixel : AData
    {
        /** static for use of generating a random pixel */
        static Random m_randomGenerator = new Random();

        /** attribute x coordinate */
        public Int16 x
        {
            get
            {
                return (Int16)coordinates[0];
            }
            set
            {
                coordinates[0] = value;
            }
        }

        /** attribute y coordinate */
        public Int16 y
        {
            get
            {
                return (Int16)coordinates[1];
            }
            set
            {
                coordinates[1] = value;
            }
        }
        /** attribute greyscale value */
        public double greyIntencity
        {
            get
            {
                return coordinates[2];
            }
            set
            {
                coordinates[2] = value;
            }
        }

       
        /** 
         * comparing function 
         * @param obj (AData) [IN].
         * @ return 0 if equal, -1 if obj is bigger than this, or 1 if smaller.
         */
        override public int compareTo(AData obj)
        {
            //by location
            CPixel arg = (CPixel)obj;
            if (arg.x == x && arg.y == y) return 0;
            if (arg.y > y) return -1;
            if (arg.y == y && arg.x > x) return -1;
            return 1;
        }
        /**
         * generates a random datum.
         * @return a randomly located AData
         */
        override public AData getRandomDatum()
        {
            CPixel tmp = new CPixel(3);
            
            tmp.id = -1;
            tmp.x = (Int16)(50 * m_randomGenerator.NextDouble());
            tmp.y = (Int16)(50 * m_randomGenerator.NextDouble());
            tmp.greyIntencity = (Int16)(255 * m_randomGenerator.NextDouble());
            return tmp;
        }
        /**
         * constructor
         * creates a base of dimension 3. (x,y,greyscale).
         * @param xval (Int16) [IN] x-value.
         * @param yval (Int16) [IN] y-value
         * @param greyval (Int16) [IN] greyscale value.
         */
        public CPixel(Int16 xval = 0, Int16 yval = 0, int greyval = 0) : base(3)
        {
            x = xval;
            y = yval;
            greyIntencity = greyval;
        }

    } // end of class CPixel
}
